package com.example.demo.alipay.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;

/**
 * 
 * <p>
 * 功能描述：两个支付宝客户端，用户可以使用任意一个. alipay-trade-sdk
 * 是对alipay-sdk-java的封装，建议使用alipay-trade-sdk.
 * </p>
 * 
 * @author lixh
 * @date 2019年3月15日 上午9:53:08
 * @version 1.0
 */
@Configuration
@EnableConfigurationProperties(AlipayProperties.class)
public class AlipayConfiguration {

	@Autowired
	private AlipayProperties alipayProperties;

	/**
	 * alipay-trade-sdk 进行配置
	 * 
	 * @return
	 */
	@Bean
	public AlipayTradeService alipayTradeService() {
		return new AlipayTradeServiceImpl.ClientBuilder().setGatewayUrl(alipayProperties.getGatewayUrl())
				.setAppid(alipayProperties.getAppid()).setPrivateKey(alipayProperties.getAppPrivateKey())
				.setAlipayPublicKey(alipayProperties.getAlipayPublicKey()).setSignType(alipayProperties.getSignType())
				.build();

	}

	/**
	 * 
	 * 方法描述:alipay-sdk-java 进行配置
	 * 
	 * @return
	 * @author lixh
	 */

	@Bean
	public AlipayClient alipayClient() {
		return new DefaultAlipayClient(alipayProperties.getGatewayUrl(), alipayProperties.getAppid(),
				alipayProperties.getAppPrivateKey(), alipayProperties.getFormate(), alipayProperties.getCharset(),
				alipayProperties.getAlipayPublicKey(), alipayProperties.getSignType());
	}

}
